import pytest
import requests
import hashlib

class UpDown():
    def setup_method(self):
        self.headers = {
               'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
               'Content-Type': 'application/json;charset=UTF-8'
        }
class UpDown2():
    @classmethod
    def setup_class(cls):
        username = 'yh'
        password = '123456'
        md5 = hashlib.md5(password.encode())  # 创建MD5对象
        password_md5 = md5.hexdigest()
        cls.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
            'Content-Type': 'application/json;charset=UTF-8'
        }
        #构造url
        url_login = r'http://192.168.190.132:3000jshERP-boot/user/login'
        #构造 data
        data_login = {'loginName': username, 'password': password_md5}
        #发送请求
        resp = requests.post(url_login, json=data_login, headers=headers, verify=False, timeout=3)
        token = resp.json()['data']['token']
        cls.headers['X-Access-Token'] = token
        # print(cls.headers)
if __name__ == '__main__':
    pytest.main()
